<template>
	<view class="page">
		<uni-card title="安全隐患清单">
			<view class="card-box">
				<view class="card-box-t u-border-bottom">
					<view class="card-box-t-item">
						<text class="num">{{ riskInventory.total_num }}</text>
						<text class="txt">应填人数</text>
					</view>
					<view class="card-box-t-item">
						<text class="num">{{ riskInventory.filled_num }}</text>
						<text class="txt">已填人数</text>
					</view>
					<view class="card-box-t-item">
						<text class="num red">{{ riskInventory.not_filled_num }}</text>
						<text class="txt">未填人数</text>
					</view>
				</view>

				<view class="card-box-b" hover-class="hover-class" @tap="openDeptList"><text>按部查看</text></view>
			</view>
		</uni-card>

		<zb-table :show-header="true" :data="tableData" :columns="tableCols" :stripe="true" :border="true"></zb-table>

		<view class="uni-pagination-box">
			<!-- 分页组件 -->
			<uni-pagination show-icon :page-size="pagination.limit" :current="pagination.page" :total="totalNum" @change="onPageChange" />
		</view>
		
		<!-- <view class="u-m-t-30"><uni-pagination v-model="pagination.page" :pageSize="pagination.limit" showIcon @change="onPageChange" /></view> -->
	</view>
</template>

<script>
import { getCurrentDate } from '@/libs/utils'

export default {
	data() {
		return {
			pagination: {
				page: 1,
				limit: 10
			},
			riskInventory: {
				total_num: 16,
				filled_num: 12,
				not_filled_num: 4
			},
			tableCols: [
				{ name: 'risk_code', label: '编号', type: 'index', fixed: true }, //operation,img,index,selection
				{ name: 'risk_name', label: '隐患名称', fixed: true, width: 160 },
				{ name: 'risk_level', label: '隐患等级' },
				{ name: 'risk_sort', label: '隐患类别' },
				{ name: 'risk_reason', label: '原因分析' },
				{ name: 'risk_control_measure', label: '关联的风险控制措施', width: 160 },
				{ name: 'risk_result', label: '关联的后果' },
				{ name: 'risk_src', label: '来源' },
				{ name: 'risk_find_time', label: '发现时间' },
				{ name: 'correct_dept', label: '整改单位/部门', width: 120 },
				{ name: 'correct_time', label: '整改时间' },
				{ name: 'correct_measure', label: '整改措施' },
				{ name: 'correct_fund', label: '整改资金' },
				{ name: 'resp_plan', label: '应急预案' },
				{ name: 'measure_verifier', label: '措施验证人' },
				{ name: 'measure_verify_time', label: '措施验证时间', width: 120 },
				{ name: 'manage_effect_verify', label: '治理效果验证情况', width: 160 },
				{ name: 'is_close', label: '是否关闭' },
				{ name: 'close_time', label: '关闭时间' }
			],
			tableData: [],
			totalNum: 0
		}
	},
	onLoad() {},
	onShow() {
		this.refreshDataList()
	},
	onReady() {},
	methods: {
		onPageChange(e) {
			//e={type,current} current为当前页，type值为：next/prev
			console.log('onPageChange: ', e)
			this.pagination.page = e.current
			this.getRiskList()
		},
		async refreshDataList() {
			this.pagination.page = 1
			await this.getRiskList()
		},
		openDeptList() {
			const url = `/pages/risk/inventory/dept/index`
			uni.navigateTo({
				url
			})
		},
		async getRiskList() {
			const params = {
				page: this.pagination.page,
				size: this.pagination.limit,
				type: 0 //获取列表的类型，1标识上报列表，0标识公示列表
			}

			try {
				const res = await uni.$uu.Api.getRiskList(params)
				console.log(res)
				if (res.code === 100) {
					this.totalNum = res.content.length
					this.tableData = res.content.map((_, index) => {
						return {
							risk_name: _.name,
							risk_level: _.level,
							risk_sort: _.category,
							risk_reason: _.reason,
							risk_control_measure: _.linkMeasure,
							risk_result: _.linkResult,
							risk_src: _.source,
							risk_find_time: _.discoveryTime,
							correct_dept: _.changeDept,
							correct_time: _.changeTime,
							correct_measure: _.changeMeasure,
							correct_fund: _.changeAmount,
							resp_plan: _.emergencyPlan,
							measure_verifier: _.verifyUser,
							measure_verify_time: _.verifyTime,
							manage_effect_verify: _.verifyResult,
							is_close: _.isClose,
							close_time: _.closeTime
						}
					})
				}
			} catch (e) {
				console.log(e)
			}
		}
	}
}
</script>

<style lang="scss" scoped>
@import '~@/common/scss/index.scss';
@import './index.scss';
</style>
